package ReviewStack;

import java.util.Stack;

public class OutStack {
    public boolean stackWay(int[] arr1,int [] arr2){
        Stack<Integer> s=new Stack<>();
        for(int i=0;i<arr1.length;i++){
            s.push(arr1[i]);
            int k=0;
            while(!s.isEmpty()&&k<arr2.length&&s.peek()==arr2[k]){
                s.pop();
                k++;
            }
        }
        return s.isEmpty();
    }
}
